{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "16e153b0",
   "metadata": {},
   "source": [
    "Problem faced before numpy \n",
    "    Python cant handel big datasets efficiently , while using datasets like weather,stock market,medical etc , we cant efficiently perfrom operations over it like looping over.\n",
    "\n",
    "Numpy solved this problem . It is abbrevated as numerical python and helps to handel large amount of data using arrays. \n",
    "Numpy arrays are 50 to 100 times faster than python and uses less memeory , also it has inbuilt optimised methods to perform many calculations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "49481df0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5]\n",
      "[1 2 3 4 5]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "python_list = [1,2,3,4,5]\n",
    "numpy_array = np.array([1,2,3,4,5])\n",
    "print(python_list)\n",
    "print(numpy_array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f18170da",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5]\n",
      "[[1 2 3]\n",
      " [4 5 6]\n",
      " [7 8 9]]\n"
     ]
    }
   ],
   "source": [
    "# 1d array \n",
    "oned_arr = np.array([1,2,3,4,5])\n",
    "print(oned_arr)\n",
    "\n",
    "twod_arr = np.array([[1,2,3],[4,5,6],[7,8,9]])\n",
    "print(twod_arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff6a4cfc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# find beat by beat a,b,c,d values\n",
    "feature_list = []\n",
    "for i in range(len(peaks_pos)-1):\n",
    "    a_index = peaks_pos[i]\n",
    "    next_a_index = peaks_pos[i+1]\n",
    "    segment = apg[a_index:next_a_index]\n",
    "\n",
    "    #require ~20% of this beat's a-amplitude \n",
    "    promi = 0.2*apg[a_index]\n",
    "\n",
    "    # local positive and negatove peaks in segment \n",
    "    local_peaks_pos,_ = find_peaks(segment,prominence=promi)\n",
    "    local_peaks_neg,_ = find_peaks(-segment,prominence=promi)\n",
    "\n",
    "    # convert to absolute index\n",
    "    local_peaks_pos += a_index\n",
    "    local_peaks_neg += a_index\n",
    "\n",
    "    # a is known\n",
    "    a_val = apg[a_index]\n",
    "\n",
    "    # find b,c,d values : first neg after a , then pos after b then neg after c\n",
    "    b_index = next((i for i in local_peaks_neg if i>a_index),None)\n",
    "    c_index = next((i for i in local_peaks_pos if b_index and i>b_index),None)\n",
    "    d_index = next((i for i in local_peaks_neg if c_index and i>c_index),None)\n",
    "\n",
    "    if all(idx is not None for idx in [a_index,b_index,c_index,d_index]) and a_val>0:\n",
    "        b_val = apg[b_index]\n",
    "        c_val = apg[c_index]\n",
    "        d_val = apg[d_index]\n",
    "        if b_val<0 and c_val>0 and d_val<0:\n",
    "            feature_list.append({\n",
    "                'a_index': a_index,\n",
    "                'b_index': b_index,\n",
    "                'c_index': c_index,\n",
    "                'd_index': d_index,\n",
    "                'a': a_val,\n",
    "                'b': b_val,\n",
    "                'c': c_val,\n",
    "                'd': d_val,\n",
    "                'b/a': abs(b_val)/a_val,\n",
    "                'd/a': abs(d_val)/a_val\n",
    "            })\n",
    "        print(f\"a-value - \",a_val)\n",
    "        print(f\"b-value - \",b_val)\n",
    "        print(f\"c-value - \",c_val)\n",
    "        print(f\"d-value - \",d_val)\n",
    "    \n",
    "print(feature_list)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
